// TOWN SCRIPT
//    Town 2: Under Greenleaf

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

if(get_flag(2,1) == 0) {
	reset_dialog();
	add_dialog_str(0,"You climb down the ladder from the back room of Tovas's home, and find yourself in some kind of storeroom under the earth. Several stone boxes have been dumped here, and construction materials litter the floor.",0);
	add_dialog_str(1,"Whilst wondering what on earth this place is for, and who dug it out, you spot a pair of heavy wooden doors to the west. A set of footprints disappear under them, clearly visible in the dust.",0);
	add_dialog_str(2,"Since you've just received the key from Mayor Stone, you wonder who could have made them - it clearly couldn't have been Roxy.",0);
	run_dialog(1);
	set_flag(2,1,1);
}

set_terrain(20,15,0);
set_terrain(20,11,0);
set_terrain(21,4,234);
set_terrain(21,6,234);
set_terrain(21,8,234);

if(get_flag(2,3) == 1) {
flip_terrain(15,5);
}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.

break;

//Ladder to Greenleaf
beginstate 10;

	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",3);
		end();
		}
		
	reset_dialog();
	add_dialog_str(0,"This ladder leads back upstairs. Do you wish to climb back up?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		print_str_color("You climb back upstairs.",3);
		move_to_new_town (0,35,15);
	} else {
		block_entry(1);
	}
break;

//Chests in first hall...
beginstate 11;
	if(get_flag(2,0) == 0) {
		message_dialog("You open this chest, half-hoping (and half-expecting) to find something worthwhile. You are sadly disappointed. At the bottom of the smooth, stone box is nothing but an abundance of fresh air.","");
		set_flag(2,0,1);
	} else {
		print_str_color("You find nothing of value",3);
	}
break;

//Library greeting
beginstate 12;
	if(get_flag(2,2) == 0) {
		message_dialog("You step through the door into this large underground room, and immediately wish you hadn't. You get a terrible sense of dread just being here. Looking around, you notice two things.","Firstly, the northern end is full of bookshelves - Tovas must have been collecting tomes for years. Secondly, a large book is lying open just in front of you. The writing looks fairly new.");
		set_flag(2,2,1);
	}
break;

//Book that tells of portal
beginstate 13;
	if(get_flag(250,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"You flick through this book - it is another journal - a non-magical one. Most of it looks uninteresting, except for an entry just a few pages from the beginning, and in particular, this passage:",0);
		add_dialog_str(1,"_The portal has been set up, and tested. Getting to the tower should now be possible even in emergencies, without any effort. In order to keep the fools in Greenleaf from finding it, I hid it in the hills to the south of the lake.",0);
		add_dialog_str(2,"_It is directly south of a huge white boulder. I even managed to power it without the usual crystals by..._",0);
		add_dialog_str(3,"After that it waffles a little about power conduits and such. Still, the fact there is a direct way to Tovas's tower is promising...",0);
		run_dialog(1);
		set_flag(100,1,1); 
		set_flag(250,1,1);
	} else {
		message_dialog("You flick through the book again, but find nothing of value.","");
}
break;

//Cutscene Book
beginstate 14;
	
	if(get_flag(2,3) == 1) {
		message_dialog("You flick through the book again. Unfortunately, there are no other entries in it - you have learned all you can.","");
	} 
	
	if(get_flag(2,3) == 0) {
		reset_dialog();
		add_dialog_str(0,"You eagerly flick through this book, hoping that it contains Tovas's notes concerning how he tracked the monster. It looks like you came up trumps - it is his journal.",0);
		add_dialog_str(1,"Do you wish to read it? It may be useful...",0);
		add_dialog_choice(0,"No (leave the book alone).");
		add_dialog_choice(1,"Yes (read the book).");
		if(run_dialog(1) == 1) {
			end();
		} else {
			message_dialog("You flick through the book, and see that each entry is just one line long, and in some strange magical tongue. Luckily, you know enough about magic to figure out what this is.","If you say the words out loud a shade will be summoned to deliver the entry. You all gather round the book, and read the last entry, dated about a week ago.");
			
			//here we go. this is probably longer than t6 too. gah. and more complex.
			//why, why, why did i do this?!
			
			//okay, set up character behind book.
			
			relocate_character(0,18,12);
			relocate_character(1,17,12);
			relocate_character(2,19,12);
			relocate_character(3,18,11);
			set_character_facing(1000,4);
			force_instant_terrain_redraw();
			
			pause(2 * get_flag(250,5));
			
			//make them "read" yay for hidden things!
			
			text_bubble_on_char(0,"Remmah et nwod,"); //missing h.
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();	
			
			text_bubble_on_char(0,"Mals oy neh na."); //missing u,w,d.
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			//switch view
			
			force_view_center(18,16);
			force_instant_terrain_redraw();
			
			//Summon Tovas shade
			
			put_effect_on_space(18,16,9,10,0);
			activate_hidden_group(1);
			force_instant_terrain_redraw();
			run_animation_sound(163);
						
			message_dialog("Suddenly, a shade appears on the platform to the south. It is silent for a moment, but quickly begins speaking in Tovas's voice. It sounds as if it's a million miles away.","");
			
			pause(3 * get_flag(250,5));
			
			text_bubble_on_char(6,"We spoke again today."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"She wants to leave Greenleaf."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"I think I have to tell"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"her about me tomorrow."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			pause(3 * get_flag(250,5));
			
			text_bubble_on_char(6,"Whenever I say that"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"I can't see her"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"during the day, she"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"accuses me of not loving her."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"So she must know."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"And soon..."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			//Kill this shade.
			
			put_effect_on_space(18,16,9,10,0);
			erase_char(6);
			force_instant_terrain_redraw();
			run_animation_sound(163);
			
			message_dialog("That seemed rather cryptic. Who is the lady Tovas was referring to? And what does she need to know?","You turn the page back, and read the previous entry.");
			
			pause(2 * get_flag(250,5));
			
			//make party "read". guess the link!!
			
			text_bubble_on_char(0,"Yadnus ekil"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(0,"si yadyreve."); //Come, come, nuclear bomb!
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			//Resummon shade
			
			put_effect_on_space(18,16,9,10,0);
			activate_hidden_group(1);
			force_instant_terrain_redraw();
			run_animation_sound(163);
			
			message_dialog("Another shade appears. It begins speaking immediately, in the same far-off way.","");
			
			pause(1 * get_flag(250,5));
			
			text_bubble_on_char(6,"Laurina and I went"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"to the lake tonight."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"She spoke about her dreams,"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"her hopes. She is so"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"fragile. So perfect..."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			pause(2 * get_flag(250,5));
			
			text_bubble_on_char(6,"I was about to tell her,"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"but it would surely mean"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"the end for us."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"I must see her tomorrow."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			pause(3 * get_flag(250,5));
			
			text_bubble_on_char(6,"I pray for the strength"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"to do what is right."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			//Kill this shade.
			
			put_effect_on_space(18,16,9,10,0);
			erase_char(6);
			force_instant_terrain_redraw();
			run_animation_sound(163);
			
			reset_dialog();
			add_dialog_str(0,"Well, that cleared things up a little. From the sounds of it, Tovas and Laurina are a couple. WERE a couple, before he left town, and before she was taken.",0);
			add_dialog_str(1,"Surprisingly though, this was the first you'd heard about it. They probably kept it from everybody, including Mayor Stone.",0);
			add_dialog_str(2,"As well as wondering why they'd do that, you also wonder what this burning issue he has to share with her really is.",0);
			add_dialog_str(3,"You turn back to the previous entry in the hope of getting some answers...",0);
			run_dialog(1);
			
			//oh, here comes the fun. shade appears, says some crap
			//then tovas appears, and you watch shade together
			//then he fills you in, and roxy gatecrashes
			//tovas goes off, you and rox talk, and then she looks around
			//You go tell stone, and go to t's tower
			
			pause(1 * get_flag(250,5));
			
			text_bubble_on_char(0,"Ytliug ot aelp"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(0,"ym degnahc evi."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw(); 
			
			//Make new shade (last time!!)
			
			put_effect_on_space(18,16,9,10,0);
			activate_hidden_group(1);
			force_instant_terrain_redraw();
			run_animation_sound(163);	
			
			message_dialog("Again, the shade begins speaking immediately:","");
			
			pause(1 * get_flag(250,5));
			
			//Make him say a few things, and then have message flash up
			//(do i like this? is this all a waste of time?)
			
			text_bubble_on_char(6,"I'm finding it harder"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"to live with what I am."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			pause(5 * get_flag(250,5));
			
			text_bubble_on_char(6,"I am a murderer."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			pause(2 * get_flag(250,5));
			
			text_bubble_on_char(6,"A monster."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			text_bubble_on_char(6,"I must drink blood to live."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
				
			text_bubble_on_char(6,"How can I tell her?"); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			pause(5 * get_flag(250,5));
			
			text_bubble_on_char(6,"I need to feed."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			//Kill this shade.
			
			put_effect_on_space(18,16,9,10,0);
			erase_char(6);
			force_instant_terrain_redraw();
			run_animation_sound(163);		
				
			message_dialog("You freeze. Your blood feels icy cold, and your heart begins beating faster. Tovas is the monster. And you can only assume he took Laurina as well.","But... it doesn't make sense. You learnt just moments ago that he loved her...");
			
			message_dialog("Suddenly, you hear something to the north. You spin around...","");
			
			force_view_center(17,12);
			set_character_facing(1000,0);
			force_instant_terrain_redraw();
			
			//open the door and have footsteps
			
			play_sound(9);
			
			pause(3 * get_flag(250,5));
			
			play_sound(58);
			flip_terrain(15,5);
			
			//ASK TOVAS WHAT HE'S DOING
			//TO BE FINISHED, WOULD BE A RELIEF
			
			//now, introduce the man
			
			activate_hidden_group(2);
			force_instant_terrain_redraw();
			
			relocate_character(7,16,5);
			force_instant_terrain_redraw();
			pause(2 * get_flag(250,5));
			
			relocate_character(7,17,6);
			set_character_facing(7,4);
			force_instant_terrain_redraw();
			pause(3 * get_flag(250,5));
			
			//make him speak
			
			text_bubble_on_char(7,"Well, this *is* a nice...");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			relocate_character(7,17,7);
			text_bubble_on_char(7,"");
			text_bubble_on_char(7,"...surprise, isn't it?");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			text_bubble_on_char(7,"");
			force_instant_terrain_redraw();
			
			reset_dialog();
			add_dialog_str(0,"It's Tovas! But dressed in all black, and looking very menacing. He must have been waiting here for you. He looks at you, and motions to the book behind you.",0);
			add_dialog_str(1,"_Ah, my diary. I shouldn't have left it lying around, although I suppose to be found out is a relief. And it was rather a good read, wasn't it?",0);
			add_dialog_str(2,"_I also suppose you'll want to know where Laurina is, and what I did with the other people I took._ He pauses for a moment, and you look around for a way to get out. He spots you doing so.",0);
			add_dialog_str(3,"_Oh come now, let's not be silly. I'd kill you before you could make it to the door. Now, I expect you'll want to go and tell everybody how evil I am, right?_",0);
			add_dialog_str(4,"You don't move. _As I thought. Well, how about this. If you can convince me to let you leave, I will. If not, I'll kill you now. Oh, and,_ he smiles, _this isn't an option you can decline._",0);
			run_dialog(1);
			
			pause(3);
			
			text_bubble_on_char(7,"Time is running out..."); 
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,5));
			
			erase_text_bubbles();
			force_instant_terrain_redraw();
			
			set_state_continue(24);
		}
	}
	
break;

//Concealed Tunnel
beginstate 15;
	if(get_flag(2,4) == 0) {
		message_dialog("As you wander down this concealed passage, you pick up the overwhelming stench of death. Fortunately, you manage not to gag. Suddenly, you freeze...","Could this be the monster's lair? Or at least where it dumped the bodies when it had finished with them? But... that would mean that either Tovas is the monster, or is at least responsible for it...");
		set_flag(2,4,1);
	}
break;

//Rats nest
beginstate 16;
	if(get_flag(2,5) == 0) {
		message_dialog("You reach the end of the tunnel, and look about. There is blood everywhere, and more than a few bones. However, they are the bones of rats and mice, not humans.","You breathe a sigh of relief - the idea that Tovas was the monster was ridiculous at best. You can't believe you let yourself believe it.");
		message_dialog("However, you are still no closer to finding the whereabouts of the missing citizens. You turn to go, but catch a glimpse of something shiny in one of the nests....","It may be worth checking out.");
		set_flag(2,5,1);
	}
break;

//Nest
beginstate 17;
	if(get_flag(2,6) == 0) {
		message_dialog("You rummage about in this nest, and find a bronze key. Somebody must have hidden it here before this place was abandoned.","");
		set_flag(2,6,1);
		change_spec_item(2,1);
	}
break;

//Wall
beginstate 18;
	if(get_flag(2,7) == 0) {
		message_dialog("As you approach this section of wall, you see that it has a large crack running down it. You could probably just about fit through.","");
		set_flag(2,7,1);
	}
break;

//End of cutscene, when Roxy comes in, and all three other paths are tied together.
beginstate 22;
	relocate_character(7,17,8);
	text_bubble_on_char(7,"You don't stand a..."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));

	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	relocate_character(7,17,9);
	text_bubble_on_char(7,"...chance in hell."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	force_view_center(17,10);
	activate_hidden_group(3);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,5));
	
	set_character_facing(8,0);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,5));
	
	text_bubble_on_char(8,"Guys...?"); 
	force_instant_terrain_redraw();
	pause(3 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	text_bubble_on_char(8,"What's going on?"); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	message_dialog("Roxy! Slightly out of breath, and looking a little worse for wear, Roxy enters the room, and glances from you to Tovas, and back. Tovas scowls. _Well, isn't this cosy. You are lucky, adventurers, that I don't wish to battle today.","But we will meet again, and soon..._");
	message_dialog("And, with that, he disappears in a flash of light.","Roxy just frowns.");
	
	put_boom_on_char(7,3,0);
	run_animation_sound(-10);
	erase_char(7);
	force_instant_terrain_redraw();
	
	text_bubble_on_char(8,"Guys...?"); 
	force_instant_terrain_redraw();
	pause(3 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	text_bubble_on_char(8,"Really, what's going on?"); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	pause(2 * get_flag(250,5));

	pause(1);
	message_dialog("You explain everything to Roxy, everything that has happened since you last spoke. She grows pale. _You need to tell Mayor Stone about..._ She stops. _Actually, we should look around first. Then, once we've done that, we'll tell the Mayor. Come on._","");
	
	
	//set flags to end this.
			set_flag(2,3,1);
			set_flag(250,2,1);
			end();
break;

beginstate 23;
	if(get_flag(2,8) == 0) {
		message_dialog("As you enter this room, you shudder. There is a coffin against the far wall. But... that would make... Tovas is a vampire?!","This isn't good...");
		set_flag(2,8,1);
	}
break;

beginstate 24;
	message_dialog("You start to panic... there's nothing you can think of that might help. Then, suddenly, it comes to you...","_We need to tell Mayor Stone about his daughter. Surely you don't want him to worry about someone he loves so dearly?_ you say."); 
	message_dialog("What you say strikes a chord with Tovas. You press the advantage, and play on the fact that he loves her too by adding _And maybe he'll be able to understand why you took her, if we explain._","");
	message_dialog("Unfortunately, it only works for a moment. Tovas shakes his head slowly, still lost in thought. Then, he snaps out of it, and glares at you.","");
	
		text_bubble_on_char(7,"Nice try."); 
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,5));
			
		erase_text_bubbles();
		force_instant_terrain_redraw();
			
		text_bubble_on_char(7,"But it didn't work."); 
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,5));
			
		erase_text_bubbles();
		force_instant_terrain_redraw();
		
		text_bubble_on_char(7,"Why should I take that risk?"); 
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,5));
			
		erase_text_bubbles();
		force_instant_terrain_redraw();
	
		message_dialog("He moves closer, and hisses _No, we have to finish this now. Before you're allowed to say ANYTHING. He moves to attack, but, at that moment, somebody else bursts into the room...","");
		set_state_continue(22);
break;

beginstate 25;
	if((get_flag(250,1) == 0) && (get_flag(2,3) == 1)) {
		message_dialog("You should look around a bit more before leaving.","");
		block_entry(1);
	}
break;